<template>
  <view class="page flex-col">
    <view class="group_3">
      <view class="section_1 flex-row mt-6">
        <view class="box_1 flex-row flex-col mt-6">
          <view class="flex-row align-center justify-start">
            <text class="text-group_1 txt red ml_20">学校名称:</text>
            <nut-input class="wp100 noborder" v-model="submitmain.name" placeholder="必填项" />
          </view>
        </view>
      </view>
      <view class="section_1 flex-row mt-6 nf">
        <view class="box_1 flex-row">
          <view class="flex-row align-center justify-start">
            <text class="text-group_1 txt red ml_20">专业名称:</text>
            <nut-input class="wp100 noborder" v-model="submitmain.major" placeholder="必填项" />
          </view>
        </view>
      </view>

      <view class="section_1 flex-row mt-6">
        <view class="box_1 flex-row">
          <view class="flex-row align-center justify-start">
            <text class="text-group_1 txt red ml_20">最高学历:</text>
            <nut-input class="wp100 noborder" v-model="submitmain.descriptions" placeholder="必填项" />
          </view>
        </view>
      </view>

      <view class="section_1 flex-row mt-6">
        <view class="box_1 time_g flex-row">
          <view class="flex-row align-center justify-start">
            <text class="text-group_1 txt red pos"></text>
            <nut-cell title="入学时间" :desc="descdate" @click="showval = true"></nut-cell>
            -
            <nut-cell title="结束时间" :desc="descdate1" @click="showval1 = true"></nut-cell>
          </view>
        </view>
      </view>

      <view class="section_13 flex-row justify-between">
        <view class="text-wrapper_5 border flex-col" @click="cancel">
          <text class="text_11">取消</text>
        </view>
        <view class="text-wrapper_6 flex-col" @click="save">
          <text class="text_12">保存</text>
        </view>
      </view>
      <nut-datepicker
        v-model="currentDate"
        v-model:visible="showval"
        :min-date="minDate"
        :max-date="maxDate"
        :is-show-chinese="true"
        :three-dimensional="false"
        @confirm="confirmbtn"
      ></nut-datepicker>
      <nut-datepicker
        v-model="currentDate1"
        v-model:visible="showval1"
        :min-date="minDate1"
        :max-date="maxDate1"
        :is-show-chinese="true"
        :three-dimensional="false"
        @confirm="confirmbtn1"
      ></nut-datepicker>
    </view>
  </view>
</template>

<script setup lang="ts">
import '@/static/common.less';
import './index.less';
import { getCurrentInstance, reactive, ref, toRaw } from 'vue';
import Taro, {
  useLoad,
  useDidShow,
  usePullDownRefresh,
  useReachBottom,
  useShareAppMessage,
  useShareTimeline,
  useTitleClick,
} from '@tarojs/taro';
import { showerr, geyDay } from '@/utils/common';

import { CategoryType, getCategoriesApi } from '@/api/categories';
import ProtoList from '@/components/proto-list/index.vue';
// import LoadMoreBottom from '@/components/load-more-bottom/index.vue';
import { getProtoListApi, ProtoType } from '@/api/proto';
import SimpleTabs from '@/components/simple-tabs/index.vue';
import { TARO_RUNTIME } from '@tarojs/runtime';
const container2 = ref(null);

// const windowInfo = Taro.getWindowInfo();
// const { proxy } = getCurrentInstance();
let query = ref({
  page: 1,
  limit: 6,
  category_id: '',
  sort_by: '',
  keywords: '',
});
let submitmain = reactive({
  id: -1,
  name: '',
  major: '',
  start_time: '',
  end_time: '',
});
let othertime = reactive({
  start_time: '',
  end_time: '',
});
const showval = ref(false);
let descdate = ref('2022年05月10日');
const minDate = new Date(1980, 0, 1);
const maxDate = new Date(2030, 10, 1);
const currentDate = new Date();
const confirmbtn = ({ selectedValue, selectedOptions }) => {
  submitmain.start_time = selectedOptions.map((option) => option.value).join('/');
  descdate.value =  selectedOptions.map((option) => option.text).join('');
  console.log(submitmain.start_time,descdate.value)

};

const showval1 = ref(false);
let descdate1 = ref('2022年05月10日');
const minDate1 = new Date(1980, 0, 1);
const maxDate1 = new Date(2030, 10, 1);
const currentDate1 = new Date();
const confirmbtn1 = ({ selectedValue, selectedOptions }) => {
  submitmain.end_time = selectedOptions.map((option) => option.value).join('/');
  descdate1.value =  selectedOptions.map((option) => option.text).join('');


};
const save = () => {
  let obj = toRaw(submitmain);
  let bool = false;
  console.log(obj);
  for (const key in obj) {
    if (bool) break;
    if (obj[key] == '') bool = true;
  }
  if (bool)
    return Taro.showToast({
      title: '请输入完整参数',
      icon: 'none',
      duration: 500,
    });
  if (new Date(submitmain.start_time) >= new Date(submitmain.end_time))
    return Taro.showToast({
      title: '开始时间要小于结束时间',
      icon: 'none',
      duration: 500,
    });
  Taro.setStorageSync('edidutionobj', JSON.stringify(obj));
  Taro.navigateBack();
};
const cancel = () => {
  Taro.getStorageSync('edidutionobj') && Taro.removeStorageSync('edidutionobj');
  Taro.navigateBack();
};

let editor = Taro.getStorageSync('editorEduction');
if (editor) {
  Taro.removeStorageSync('edidutionobj');
  submitmain = reactive(JSON.parse(editor));
  descdate.value = geyDay(new Date(submitmain.start_time));
  descdate1.value = geyDay(new Date(submitmain.end_time));
}
</script>
